//
//  ItemTableCell.m
//  checkApp
//
//  Created by ma on 2017/6/13.
//  Copyright © 2017年 ma. All rights reserved.
//

#import "ItemTableCell.h"

@implementation ItemTableCell
{
    UILabel *titleLab;
    UILabel *statusLab;
    UIView *sepView;
    UIImageView *rightView;
}

- (void)_initView {
    [super _initView];
//    self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
//    self.accessoryType = UITableViewCellAccessoryNone;
    
    titleLab = [UILabel labelWithFrame:CGRectZero text:@"" font:15.0*boringScale textColor:color(0, 0, 0, 0.9)];
    titleLab.numberOfLines = 0;
    [self.contentView addSubview:titleLab];
    [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(10*boringScale);
        make.top.mas_equalTo(10*boringScale);
        make.trailing.mas_equalTo(-70*boringScale);
        make.height.mas_greaterThanOrEqualTo(30*boringScale);
    }];
    
    statusLab = [UILabel labelWithFrame:CGRectZero text:@"" font:13.0*boringScale textColor:color(0, 0, 0, 0.9)];
    statusLab.textAlignment = 2;
    [self.contentView addSubview:statusLab];
    [statusLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(titleLab.mas_trailing).offset(5*boringScale);
        make.centerY.mas_equalTo(self.contentView);
        make.trailing.mas_equalTo(-17*boringScale);
        make.height.mas_equalTo(20*boringScale);
    }];
    
    rightView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"more"]];
    [self.contentView addSubview:rightView];
    [rightView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.contentView);
        make.trailing.mas_equalTo(-5*boringScale);
        make.height.mas_equalTo(13*boringScale);
        make.width.mas_equalTo(8*boringScale);
    }];
    
    sepView = [[UIView alloc] init];
    sepView.backgroundColor = sepline_color;
    [self.contentView addSubview:sepView];
    [sepView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(0);
        make.trailing.mas_equalTo(0);
        make.height.mas_equalTo(1);
        make.bottom.mas_equalTo(0);
    }];

}

- (void)setItemModel:(ItemModel *)itemModel {
    if (_itemModel != itemModel) {
        _itemModel = itemModel;
    }
    titleLab.text = itemModel.title;
//    NSString *dateDD = [NSString stringWithFormat:@"%ld", (long)[[NSDate date] timeIntervalSince1970]];
    CGFloat timePP = [[NSDate date] timeIntervalSince1970];
    if (timePP < [itemModel.startTime floatValue]) {
        statusLab.text = @"未开始";
        rightView.hidden = YES;
        statusLab.textColor = red_color;
    }else if (timePP > [itemModel.endTime floatValue]) {
        statusLab.text = @"已过期";
        rightView.hidden = YES;
        statusLab.textColor = [UIColor grayColor];
    }else {
        statusLab.text = @"进行中";
        rightView.hidden = NO;
        statusLab.textColor = color(140, 219, 86, 0.8);
    }
    
//    [MYFactoryManager]
}

@end
